﻿<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
             x:Class="Apps.Yunwei.AuthorityWidget"
            xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:Apps.Yunwei.ViewModels">
    <UserControl.Resources>
        <sdk:HierarchicalDataTemplate x:Key="DataTemplate" ItemsSource="{Binding Children}">
            <CheckBox IsThreeState="{Binding HasSubs}"
                      IsChecked="{Binding IsChecked,Mode=TwoWay}">
                <CheckBox.Content>
                    <StackPanel Orientation="Horizontal">
                        <Border HorizontalAlignment="Left" VerticalAlignment="Center"
                                Background="{Binding Background}">
                            <Image Source="{Binding ImageUrl1}" Width="16" Height="16"/>
                        </Border>
                        <TextBlock Text="{Binding Caption}" Margin="2,2,0,2"/>
                    </StackPanel>
                </CheckBox.Content>
            </CheckBox>
        </sdk:HierarchicalDataTemplate>
    </UserControl.Resources>
    <UserControl.DataContext>
        <local:AuthorityViewModel/>
    </UserControl.DataContext>
    <Grid x:Name="LayoutRoot" Margin="5">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.2*" />
            <ColumnDefinition Width="5" />
            <ColumnDefinition Width="0.3*" />
            <ColumnDefinition Width="5" />
            <ColumnDefinition Width="0.2*" />
        </Grid.ColumnDefinitions>
        <!--角色清单-->
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <ListBox ItemsSource="{Binding Roles}" SelectedItem="{Binding SelectedItem,Mode=TwoWay}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="3,1">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <TextBlock Grid.Row="0" Text="{Binding Code}"
                                       FontSize="6" FontStyle="Italic" Foreground="Gray"/>
                            <TextBlock Grid.Row="1" Text="{Binding Caption}"/>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            <StackPanel Grid.Row="1">
                <Button Content="刷新" Margin="3" Cursor="Hand"
                        Command="{Binding RefreshRoleCommand}"/>
            </StackPanel>
            <toolkit:BusyIndicator IsBusy="{Binding RoleIsBusy}" Grid.RowSpan="2" />
        </Grid>
        <!--专题模块-->
        <Grid Grid.Column="2">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <sdk:TreeView ItemsSource="{Binding Datas}" ItemTemplate="{StaticResource DataTemplate}"/>
            <StackPanel Grid.Row="1">
                <Button Content="保存" Margin="3" Command="{Binding SaveTopicCommand}"/>
                <Button Content="刷新" Margin="3" Command="{Binding RefreshTopicCommand}"/>
            </StackPanel>
            <toolkit:BusyIndicator IsBusy="{Binding TopicIsBusy}" Grid.RowSpan="2"/>
        </Grid>
        <!--用户清单-->
        <Grid Grid.Column="4">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <ListBox ItemsSource="{Binding Users}" SelectedItem="{Binding SelectedItem,Mode=TwoWay}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="3,1">
                            <CheckBox IsChecked="{Binding Selected,Mode=TwoWay}" Content="{Binding Caption}" />
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            <StackPanel Grid.Row="1">
                <Button Content="保存" Margin="3" Command="{Binding SaveUserCommand}"/>
                <Button Content="刷新" Margin="3" Command="{Binding RefreshUserCommand}"/>
            </StackPanel>
            <toolkit:BusyIndicator IsBusy="{Binding UserIsBusy}" Grid.RowSpan="2"/>
        </Grid>
        <!--操作面板-->
        <Grid Grid.Column="6">
        </Grid>
    </Grid>
</UserControl>
